import { SheetManager } from "../../ccc3-framework-core/framework/modules/sheetManager";
import { GameStoreDetailBase } from "./Sheets"
export class GameStoreDetail extends GameStoreDetailBase {
  //id索引
  public static get(id: any) {
    if ((this as any)[id]) return (this as any)[id];
    return SheetManager.get("GameStoreDetail", id, GameStoreDetail);
  }
  public static getAll(): GameStoreDetail[] {
    return SheetManager.getAllSheets("GameStoreDetail", GameStoreDetail);
  }
  public static getStoreDetailByDetailId(detailId: number): GameStoreDetail {
    let all = this.getAll();
    for (let i = 0; i < all.length; i++) {
      if (all[i].DetailId == detailId) {
        return all[i];
      }
    }
  }

  public static getDetailListByDetailId(...detailIdArray: number[]): Array<GameStoreDetail> {
    let all = this.getAll();
    let retValue: Array<GameStoreDetail> = [];
    for (let i = 0; i < all.length; i++) {
      if (detailIdArray.indexOf(all[i].DetailId) > -1) {
        retValue.push(all[i])
      }
    }
    return retValue;
  }

  public static getStoreByCategoryId(...categoryArray: number[]): Array<GameStoreDetail> {
    let all = this.getAll();
    let retValue: Array<GameStoreDetail> = [];
    for (let i = 0; i < all.length; i++) {
      if (categoryArray.indexOf(all[i].CategoryId) > -1) {
        retValue.push(all[i]);
      }
    }
    return retValue;
  }

  public static getStoreByCategoryIdAndParentId(categoryId: number, ...parentArray: number[]): Array<GameStoreDetail> {
    let all = this.getAll();
    let retValue: Array<GameStoreDetail> = [];
    for (let i = 0; i < all.length; i++) {
      if (categoryId == all[i].CategoryId && parentArray.indexOf(all[i].ParentId) > -1) {
        retValue.push(all[i]);
      }
    }
    return retValue;
  }

  /**
   * 货架的容量
   * @param rackId 
   * @param level 
   */
  public static getRackNum(rackId: number, level: number) {
    var stallsInfo = this.getStoreDetailByDetailId(rackId);
    return stallsInfo.StoreNum + (stallsInfo.UpStoreNum * level);
  }


  public static getStoreByImg3DName(img3DName: string): GameStoreDetail {
    let all = this.getAll();
    for (let i = 0; i < all.length; i++) {
      if (all[i].Img3DName == img3DName) {
        return all[i];
      }
    }
    return null;
  }
}